package com.fhz.main.init

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import com.fhz.common.init.IModuleInit
import java.lang.reflect.InvocationTargetException

/**
 * 时间:2023/4/6
 * @author Mr.Feng
 * 简述: main的启动类
 * 本来是通过反射来启动的.但是p版本以后不能用了.
 */
class MainModuleInit : IModuleInit {

    override fun init(context: Context) {
        try {
            @SuppressLint("PrivateApi")
            val activityThread = Class.forName("android.app.ActivityThread")
            val thread = activityThread.getMethod("currentActivityThread").invoke(null)
            val app = activityThread.getMethod("getApplication").invoke(thread) ?: throw NullPointerException("you should init first")
        } catch (e: NoSuchMethodException) {
            e.printStackTrace()
        } catch (e: IllegalAccessException) {
            e.printStackTrace()
        } catch (e: InvocationTargetException) {
            e.printStackTrace()
        } catch (e: ClassNotFoundException) {
            e.printStackTrace()
        }
    }
}